package com.miguo.utils;

import android.content.Context;
import android.widget.Toast;

import com.miguo.framework.view.CustomToast;

import java.util.regex.Pattern;

/**
 * File Names: AppUtils
 * Describe:
 * User: LinXiaoZhi(87100854@qq.com)
 * Date: 2015-07-25
 * Time: 11:50
 */
public class AppUtils {
    public static int generaRandom(int random) {
        return (int) (Math.random() * random);
    }


    public static boolean isEmail(String email) {
        return Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}").matcher(email).matches();
    }

    public static boolean isQQ(String qq) {
        return Pattern.compile("[1-9][0-9]{4,14}").matcher(qq).matches();
    }

    public static boolean isMobilePhone(String phone) {
        String str = phone;
        if (phone.contains(" ")) {
            str = phone.replaceAll(" ", "");
        }
        phone = str;
        if (str.contains("-")) {
            phone = str.replaceAll("-", "");
        }
        return Pattern.compile("(1)\\d{10}$").matcher(phone).matches();
    }


    public static void showTaoToast(Context context, int resources) {
        CustomToast toast = CustomToast.getInstance(context);
        toast.setMessage(context.getResources().getString(resources));
        toast.showTime(1000);
        toast.show();
    }

    public static void showTaoToast(Context context, String message) {
        CustomToast toast = CustomToast.getInstance(context);
        toast.setMessage(message);
        toast.showTime(1000);
        toast.show();
    }

    public static void showToast(Context context, int resources) {
        Toast.makeText(context, resources, Toast.LENGTH_SHORT).show();
    }

    public static void showToast(Context context, String message) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }
}
